<?php
$dataContent = "";
$tagid = "";
$tagname = "";
$dataComment = "";
$siteID= "";
$newComment = "";
$currentTag = new Xmls();

if(@$_GET['editcontent'])
	$dataContent = $_GET['editcontent'];

if(@$_GET['tagid']){
	$tagid = $_GET['tagid'];
}
if(@$_GET['tagname'])
	$tagname = $_GET['tagname'];

if(@$_GET['editcomment'])
	$dataComment = $_GET['editcomment'];
	
if(@$_GET['siteId']){
	
	$siteID = $_GET['siteId'];
	
	$currentTag = $XML1 -> getTag($siteID); 
}
else{
	
	$currentTag = $XML1 -> getTag($tagid); 
}

$sqlUpdateContent ="";


	

if($tagname == "title"){
	
	if(@$obTagTitle = $XML1 -> getSiteChildrenByName($currentTag->getID(),"title")){
		
		$titleAttributeParameter = $obTagTitle -> GetAttibuteParameterByKey("value");
	
		$oldComment = $titleAttributeParameter['at_comment'];
		
		$newComment = $oldComment."\n"."------------------------------------------\n".$dataComment."\n"." by ".$USER -> getID()."   ".date("Y-m-d H:i:s",time())."\n";
	
		$sqlUpdateContent = "UPDATE ".$PROJECT_DB_TABLES["atri"]." SET at_value=\"".rawurlencode($dataContent)."\",at_comment=\"".$newComment."\",at_modifiedby = \"".$USER -> getID()."\",at_modified = \"".date("Y-m-d H:i:s",time())."\" WHERE at_xml_id = \"".$tagid."\" AND at_name = \"value\"";
	}
}
else{

	$currentTag = $XML1 -> getTag($tagid); 

	$oldComment = $currentTag -> getData('x_comment');

	$newComment = $oldComment."\n"."------------------------------------------\n".$dataComment."\n"." by ".$USER -> getID()."   ".date("Y-m-d H:i:s",time())."\n";

	$sqlUpdateContent = "UPDATE ".$PROJECT_DB_TABLES["tags"]." SET x_content=\"".rawurlencode($dataContent)."\",x_comment=\"".$newComment."\",x_modifiedby = \"".$USER -> getID()."\",x_modified = \"".date("Y-m-d H:i:s",time())."\" WHERE x_id = \"".$tagid."\"";
}

if(executeSQLQuery($sqlUpdateContent)){
	
	if($tagname != "title"){
	
		$arrEngTag = getTagByID(getEnglishID($currentTag -> getID()));
	
		addContent("<b>Content:</b>".$arrEngTag[0]['x_content']."<br/>".$dataContent."<br/>");
		
		addContent("<b>Comment:</b><br/><textarea readonly=\"\" cols=\"60\" rows=\"10\">".$newComment."</textarea>");
		
		addContent("<a href=\"javascript:void(0)\" onclick=\"onclick_xmlDataEditor('".$tagid."','".$tagname."','".$currentTag -> getData('x_section')."')\">edit</a>");	
	}
	else{	
		
		LoadXML();
		
		if(@$obTagTitle = $XML1 -> getSiteChildrenByName($currentTag->getID(),"title")){
			
			$attParameter = $obTagTitle -> GetAttibuteParameterByKey('value');
		
			$EnglishId = getEnglishID($attParameter['at_id']);
		
			$arrEngAtr = getAtrByID($EnglishId);
		
			addContent ("<b>Title:</b><br/>".$arrEngAtr[0]['at_value']."(EN)<br/>".$obTagTitle -> GetAttributeByKey("value")."<br/>");
		
			addContent("<b>Title Comment:</b><br/><textarea readonly=\"readonly\" cols=\"60\" rows=\"10\">".$newComment."</textarea><br/>");
		
			addContent("<a href=\"javascript:void(0)\" onclick = \"onclick_titleEditor('".$siteID."','value','".$tagid."','".$currentTag -> getData('x_section')."')\">Edit</a>");
		}
		
		//".$obTagTitle -> GetAttributeByKey("value")."<a href=\"javascript:void(0)\" onclick = \"onclick_titleEditor('".$currentTag->getID()."','value','".$titleID."')\">Edit</a>
	}
}
else{
	
	addContent("updatefail");
}

?>